<?php

class Application_Model_Builder_Offer{
	
	public function create(Application_Model_Object $object, Application_Model_User $user, $class_name, $offertype, 
							$price, $period = null, $priceCurrency = null, $avalability = null, $status = null,  
							$startDate = null, $endDate = null, $description = null, $addresses = null){
		$offerValues = array(
						'user' 				=> $user,
						'object'			=> $object,
						'price'				=> $price,
						'price_currency'	=> ($priceCurrency ? $priceCurrency : '€'),
						'avalability'		=> ($avalability ? $avalability : ''),
						//new or occasion 
						'status'			=> ($status ? $status : 'occasion'),
						'start_date'		=> date('Y-m-d H:i:s'),
						'end_date'			=> date('Y-m-d H:i:s')+(60*60*24*7), // 7 days later
						'description'		=> $description,
						'addresses'			=> ($addresses ? $addresses : array()),
						'period'			=> $period,
				);
		
		switch ($offertype){
			//in case of sale
			case 1:
				$sale = new Application_Model_Sale($offerValues);
				$saleMapper = new Application_Model_SaleMapper();
				$sale->setSaleId($saleMapper->save($sale));
				return $sale;
				break;
			//in case of rent
			case 2:
				$rent = new Application_Model_Rent($offerValues);
				$rentMapper = new Application_Model_RentMapper();
				$rent->setRentId($rentMapper->save($rent));
				return $rent;
				break;
			
			default:
				return null;
		}
		
	}
}